package com.yc;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Test9_udp_reciver {
    public static void main(String[] args) throws IOException {
        byte buf[] = new byte[1024];//字节数组，用于缓冲数据
        DatagramPacket dp =new DatagramPacket(buf,buf.length);
        DatagramSocket ds =new DatagramSocket(33333);
        ByteArrayOutputStream baos =new ByteArrayOutputStream();
        while(true){
            System.out.println("阻塞式的 recive方法");
            ds.receive(dp);
            System.out.println(new String(buf,0,dp.getLength()));
            baos.write(buf,0,dp.getLength());
            baos.flush();
        }
    }
}
